package com.rd.student.ruanjian.class3.gaochenxi.day0801;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

public class SortTest {
   public static void main(String[] args) {
      Person[] persons = new Person[4];
      persons[0] = new Person(56, "A", "1981-10-03");
      persons[1] = new Person(56, "B", "1981-10-03");
      persons[2] = new Person(103, "C", "2002-12-15");
      persons[3] = new Person(4, "D", "1900-10-09");

      for (int i = 0; i < persons.length - 1; i++) {
         for (int j = persons.length - 1; j > i; j--) {
            Person person = persons[i];
            Person person1 = persons[j];
            if (person.compareTo(person1)>0) {
               Person temp = persons[i];
               persons[i] = persons[j];
               persons[j] = temp;
            }
         }
      }


//      ArrayList<Person> arrayList = new ArrayList();
//      for (int i = 0; i < persons.length; i++) {
//         arrayList.add(persons[i]);
//      }

//      for(int i=0;i<arrayList.size();i++){
//         for(int j=0;j<arrayList.size();j++){
//            int n=arrayList.get(i).compareTo(arrayList.get(i));
//            if(n==1){
//               Person person=arrayList.get(i);
//               arrayList.set(i,arrayList.get(j));
//               arrayList.set(j,person);
//            }
//         }
//      }

      //冒泡排序
//      for (int i = 0; i < arrayList.size() - 1; i++) {
//         for (int j = 0; j < arrayList.size() - 1 - i; j++) {
//            if (arrayList.get(i).getAge() > arrayList.get(i + 1).getAge()) {
//               Person temp = arrayList.get(i);
//               arrayList.set(i, arrayList.get(j));
//               arrayList.set(j, temp);
//            }
//         }
//      }
      System.out.println(Arrays.toString(persons));
   }
}

class Person implements Comparable {
   private int age;
   private String name;

   private String dates;

   public Person() {
   }

   public Person(int age, String name, String dates) {
      this.age = age;
      this.name = name;
      this.dates = dates;
   }

   public int getAge() {
      return age;
   }

   public String getName() {
      return name;
   }

   public String getDates() {
      return dates;
   }

   @Override
   public String toString() {
      return "Person{" +
            "age=" + age + ", dates='" + dates + '\'' + '}';
   }

   @Override
   public int compareTo(Object o) {
      if (o == this) {
         return 0;
      }

      if (o instanceof Person) {
         Person person = (Person) o;
         return Double.compare(this.age, person.age);
//         if (compare != 0) {
//            Long func = Func(this);
//            Long func1 = Func(person);
//            return Long.compare(func, func1);
//         }
      }
      throw new RuntimeException("类型不匹配");
   }

   public static Long Func(Person person) {
      // date转时间戳
//      Date date = new Date();
//      long dateTimeStamp = date.getTime();
//      // Calender转时间戳
//      Calendar calendar = Calendar.getInstance();
//      long calTimeStamp = calendar.getTime().getTime();
      // String转时间戳
      Timestamp ts = Timestamp.valueOf(person.getDates());
      long strTimeStamp = ts.getTime();
      // 获取秒数
      Long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));

      return second;//通过这个秒数来比较大小
   }
}
